/*
 * p10891.cpp
 *
 *  Created on: 2013-7-19
 *      Author: zy
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn = 110;
int s[maxn], a[maxn], dp[maxn][maxn];
int n;
int main()
{
	while (scanf("%d", &n) && n)
	{
		s[0] = 0;
		for (int i = 1; i <= n; i++)
		{
			scanf("%d", &a[i]);
			s[i] = s[i - 1] + a[i];
		}
		for (int i = n; i >= 1; i--)
		{
			dp[i][i] = a[i];
			for (int j = i + 1; j <= n; j++)
			{
				int m = 0;
				for (int k = i + 1; k <= j; k++)
					m = min(m, dp[k][j]);
				for (int k = i; k < j; k++)
					m = min(m, dp[i][k]);
				dp[i][j] = s[j] - s[i - 1] - m;
			}
		}
		printf("%d\n", 2 * dp[1][n] - s[n]);

	}

	return 0;
}
